package io.netty.codec;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import lombok.extern.slf4j.Slf4j;

/**
 * @author Verlet
 * @date 2023-02-06 21:42
 */
@Slf4j
public class ServerHandler extends SimpleChannelInboundHandler<MyDataInfo.MyMessage> {


    @Override
    protected void channelRead0(ChannelHandlerContext ctx, MyDataInfo.MyMessage msg) throws Exception {
        if (msg.getDataType().equals(MyDataInfo.MyMessage.DataType.UserType)) {
            MyDataInfo.User user = msg.getUser();
            log.info("User: id = " + user.getId() + ", name = " + user.getName());
        } else if (msg.getDataType().equals(MyDataInfo.MyMessage.DataType.WorkerType)) {
            MyDataInfo.Worker worker = msg.getWorker();
            log.info("Worker: age = " + worker.getAge() + ", name = " + worker.getName());
        }

    }
}
